home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / instal.zip / WSLIB / GAUGE.C < prev    next >
C/C++ Source or Header  |  1991-06-12  |  16KB  |  422 lines

  1. /*----------------------------------------------------------------------------*\
  2. |   PROGRESS.C
  3. \*----------------------------------------------------------------------------*/
  4.  
  5. /*----------------------------------------------------------------------------*\
  6. |                                                                              |
  7. |   g e n e r a l   c o n s t a n t s                                          |
  8. |                                                                              |
  9. \*----------------------------------------------------------------------------*/
  10.  
  11. /*----------------------------------------------------------------------------*\
  12. |                                                                              |
  13. |   i n c l u d e   f i l e s                                                  |
  14. |                                                                              |
  15. \*----------------------------------------------------------------------------*/
  16.  
  17. #include "lobotomy.h"
  18. #include <windows.h>
  19.  
  20. /*  macros used to define functions:
  21.  *
  22.  *    EXPORT        - This function can be called from external to this DLL
  23.  *    PUBLIC        - This function can be called from another file
  24.  *    PRIVATE     - This function can only be called from inside this file
  25.  *
  26.  *  eg      int EXPORT foo();
  27.  *
  28.  * CEXPORT, CPUBLIC, and CPRIVATE are the same but use CDECL calling convention.
  29.  */
  30. #ifndef EXPORT
  31.     #define EXPORT          FAR  PASCAL
  32.     #define PUBLIC          FAR  PASCAL
  33.     #define PRIVATE         NEAR PASCAL
  34.     #define CEXPORT         FAR  cdecl
  35.     #define CPUBLIC         FAR  cdecl
  36.     #define CPRIVATE        NEAR cdecl
  37. #endif
  38.  
  39.  
  40. #include "ws.h"
  41. #include "..\install.h"
  42. #include "gauge.h"
  43.  
  44. /*----------------------------------------------------------------------------*\
  45. |                                                                              |
  46. |   g l o b a l   v a r i a b l e s                                            |
  47. |                                                                              |
  48. \*----------------------------------------------------------------------------*/
  49.  
  50. static HWND    ghWnd = NULL;
  51. static int    iCnt = 0;
  52. static FARPROC  fpxProDlg;
  53. static DWORD    rgbFG;
  54. static DWORD    rgbBG;
  55.  
  56. #define BAR_RANGE 0
  57. #define BAR_POS   2
  58.  
  59. #define BAR_SETRANGE  WM_USER+BAR_RANGE
  60. #define BAR_SETPOS    WM_USER+BAR_POS
  61. #define BAR_DELTAPOS  WM_USER+4
  62.  
  63. #ifndef COLOR_HIGHLIGHT
  64.     #define COLOR_HIGHLIGHT      (COLOR_APPWORKSPACE + 1)
  65.     #define COLOR_HIGHLIGHTTEXT   (COLOR_APPWORKSPACE + 2)
  66. #endif
  67.  
  68. #define COLORBG  rgbBG
  69. #define COLORFG  rgbFG
  70.  
  71. /*----------------------------------------------------------------------------*\
  72. |                                                                              |
  73. |   f u n c t i o n   d e f i n i t i o n s                                    |
  74. |                                                                              |
  75. \*----------------------------------------------------------------------------*/
  76.  
  77. BOOL PUBLIC ProDlgProc(HWND, unsigned, WORD, LONG);
  78. LONG PUBLIC ProBarProc(HWND, unsigned, WORD, LONG);
  79.  
  80. /*----------------------------------------------------------------------------*\
  81. |                                                                              |
  82. |   E x t e r n a l   d e f i n i t i o n s                                    |
  83. |                                                                              |
  84. \*----------------------------------------------------------------------------*/
  85.  
  86. /*----------------------------------------------------------------------------*\
  87. |   ProInit( hPrev,hInst )                               |
  88. |                                                                              |
  89. |   Description:                                                               |
  90. |       This is called when the application is first loaded into               |
  91. |    memory.  It performs all initialization.                   |
  92. |                                                                              |
  93. |   Arguments:                                                                 |
  94. |    hPrev       instance handle of previous instance                |
  95. |    hInst       instance handle of current instance                   |
  96. |                                                                              |
  97. |   Returns:                                                                   |
  98. |       TRUE if successful, FALSE if not                                       |
  99. |                                                                              |
  100. \*----------------------------------------------------------------------------*/
  101.  
  102. BOOL PUBLIC ProInit (hPrev,hInst)
  103.     HANDLE hPrev;
  104.     HANDLE hInst;
  105. {
  106.     WNDCLASS   rClass;
  107.  
  108.     if (!hPrev)
  109.     {
  110.        rClass.hCursor         = LoadCursor(NULL,IDC_ARROW);
  111.        rClass.hIcon         = NULL;
  112.        rClass.lpszMenuName   = NULL;
  113.        rClass.lpszClassName  = PRO_CLASS;
  114.        rClass.hbrBackground  = (HBRUSH)COLOR_WINDOW+1;
  115.        rClass.hInstance      = hInst;
  116.        rClass.style         = CS_HREDRAW | CS_VREDRAW;
  117.        rClass.lpfnWndProc    = ProBarProc;
  118.        rClass.cbClsExtra     = 0;
  119.        rClass.cbWndExtra     = 2*sizeof(WORD);
  120.  
  121.        if (!RegisterClass(&rClass))
  122.           return FALSE;
  123.     }
  124.  
  125.     if (fMono)
  126.     {
  127.         rgbBG = RGB(0,0,0);
  128.         rgbFG = RGB(255,255,255);
  129.     }
  130.     else
  131.     {
  132.         rgbBG = RGB(0,0,255);
  133.         rgbFG = RGB(255,255,255);
  134.     }
  135.     return TRUE;
  136. }
  137.  
  138. void PUBLIC ProClear(HWND hDlg)
  139. {
  140.     if (!hDlg)
  141.         hDlg = ghWnd;
  142.  
  143.     SetDlgItemText (hDlg, ID_STATUS1, szNull);
  144.     SetDlgItemText (hDlg, ID_STATUS2, szNull);
  145.     SetDlgItemText (hDlg, ID_STATUS3, szNull);
  146.     SetDlgItemText (hDlg, ID_STATUS4, szNull);
  147. }
  148.  
  149. /*---------------------------------------------------------------------------*\
  150. |   ControlInit( hPrev,hInst )                                                 |
  151. |                                                                              |
  152. |   Description:                                                               |
  153. |       This is called when the application is first loaded into               |
  154. |       memory.  It performs all initialization.                               |
  155. |                                                                              |
  156. |   Arguments:                                                                 |
  157. |       hPrev      instance handle of previous instance                        |
  158. |       hInst      instance handle of current instance                         |
  159. |                                                                              |
  160. |   Returns:                                                                   |
  161. |       TRUE if successful, FALSE if not                                       |
  162. |                                                                              |
  163. \*----------------------------------------------------------------------------*/
  164.  
  165. BOOL PUBLIC ControlInit (hPrev,hInst)
  166.     HANDLE hPrev;
  167.     HANDLE hInst;
  168. {
  169.     WNDCLASS    cls;
  170.  
  171.     if (!hPrev) {
  172.         cls.hCursor        = LoadCursor(NULL,IDC_ARROW);
  173.         cls.hIcon          = NULL;
  174.         cls.lpszMenuName   = NULL;
  175.         cls.lpszClassName  = "stext";
  176.         cls.hbrBackground  = (HBRUSH)COLOR_WINDOW+1;
  177.         cls.hInstance      = hInst;
  178.         cls.style          = CS_HREDRAW | CS_VREDRAW;
  179.         cls.lpfnWndProc    = fnText;
  180.         cls.cbClsExtra     = 0;
  181.         cls.cbWndExtra     = 0;
  182.  
  183.         if (! RegisterClass(&cls) )
  184.            return FALSE;
  185.     }
  186.     
  187.     return TRUE;
  188. }
  189.  
  190. /*----------------------------------------------------------------------------*\
  191. |   ProDlgProc( hWnd, uiMessage, wParam, lParam )                   |
  192. |                                                                              |
  193. |   Description:                                                               |
  194. |    The window proc for the Progress dialog box                   |
  195. |                                                                              |
  196. |   Arguments:                                                                 |
  197. |    hWnd        window handle for the dialog                   |
  198. |       uiMessage       message number                                         |
  199. |       wParam          message-dependent                                      |
  200. |       lParam          message-dependent                                      |
  201. |                                                                              |
  202. |   Returns:                                                                   |
  203. |       0 if processed, nonzero if ignored                                     |
  204. |                                                                              |
  205. \*----------------------------------------------------------------------------*/
  206.  
  207. BOOL EXPORT ProDlgProc( hDlg, uiMessage, wParam, lParam )
  208.     HWND     hDlg;
  209.     unsigned uiMessage;
  210.     WORD     wParam;
  211.     long     lParam;
  212. {
  213.     switch (uiMessage) {
  214.  
  215.        case WM_INITDIALOG:
  216.           ProClear(hDlg);
  217.           wsDlgInit(hDlg);
  218.           return TRUE;
  219.  
  220.        case WM_COMMAND:
  221.           if ( wParam == ID_CANCEL )
  222.              PostMessage(hwndWS,WM_COMMAND,ID_EXITSETUP,0L);
  223.           break;
  224.     }
  225.     return FALSE;
  226. }
  227.  
  228. /*----------------------------------------------------------------------------*\
  229. |   ProBarProc( hWnd, uiMessage, wParam, lParam )                   |
  230. |                                                                              |
  231. |   Description:                                                               |
  232. |    The window proc for the Progress Bar chart                   |
  233. |                                                                              |
  234. |   Arguments:                                                                 |
  235. |    hWnd        window handle for the dialog                   |
  236. |       uiMessage       message number                                         |
  237. |       wParam          message-dependent                                      |
  238. |       lParam          message-dependent                                      |
  239. |                                                                              |
  240. |   Returns:                                                                   |
  241. |       0 if processed, nonzero if ignored                                     |
  242. |                                                                              |
  243. \*----------------------------------------------------------------------------*/
  244.  
  245. LONG EXPORT ProBarProc( hWnd, uiMessage, wParam, lParam )
  246.     HWND     hWnd;
  247.     unsigned uiMessage;
  248.     WORD     wParam;
  249.     long     lParam;
  250. {
  251.     PAINTSTRUCT rPS;
  252.     RECT    rc1,rc2;
  253.     WORD    dx,dy,x;
  254.     WORD    iRange,iPos;
  255.     char    ach[30];
  256.     DWORD    dwExtent;
  257.  
  258.     switch (uiMessage) {
  259.         case WM_CREATE:
  260.         SetWindowWord (hWnd,BAR_RANGE,100);
  261.         SetWindowWord (hWnd,BAR_POS,0);
  262.             return 0L;
  263.  
  264.     case BAR_SETRANGE:
  265.     case BAR_SETPOS:
  266.         SetWindowWord (hWnd,uiMessage-WM_USER,wParam);
  267.         InvalidateRect (hWnd,NULL,FALSE);
  268.         UpdateWindow(hWnd);
  269.             return 0L;
  270.  
  271.     case BAR_DELTAPOS:
  272.         iPos = GetWindowWord (hWnd,BAR_POS);
  273.         SetWindowWord (hWnd,BAR_POS,iPos+wParam);
  274.         InvalidateRect (hWnd,NULL,FALSE);
  275.         UpdateWindow(hWnd);
  276.             return 0L;
  277.  
  278.         case WM_PAINT:
  279.         BeginPaint(hWnd,&rPS);
  280.         GetClientRect (hWnd,&rc1);
  281.         FrameRect(rPS.hdc,&rc1,GetStockObject(BLACK_BRUSH));
  282.         InflateRect(&rc1,-1,-1);
  283.         rc2 = rc1;
  284.         iRange = GetWindowWord (hWnd,BAR_RANGE);
  285.             iPos   = GetWindowWord (hWnd,BAR_POS);
  286.  
  287.             if (iRange <= 0)
  288.                 iRange = 1;
  289.  
  290.         if (iPos > iRange)    // make sure we don't go past 100%
  291.             iPos = iRange;
  292.  
  293.         dx = rc1.right;
  294.         dy = rc1.bottom;
  295.         x  = (WORD)((DWORD)iPos * dx / iRange) + 1;
  296.  
  297.         wsprintf (ach,"%3d%%",(WORD)((DWORD)iPos * 100 / iRange));
  298.         dwExtent = GetTextExtent (rPS.hdc,ach,4);
  299.  
  300.         rc1.right = x;
  301.         rc2.left  = x;
  302.  
  303.         SetBkColor(rPS.hdc,COLORBG);
  304.         SetTextColor(rPS.hdc,COLORFG);
  305.         ExtTextOut (rPS.hdc,
  306.         (dx-LOWORD(dwExtent))/2,(dy-HIWORD(dwExtent))/2,
  307.         ETO_OPAQUE | ETO_CLIPPED,
  308.         &rc1,
  309.         ach,4,NULL);
  310.  
  311.             SetBkColor(rPS.hdc,COLORFG);
  312.             SetTextColor(rPS.hdc,COLORBG);
  313.         ExtTextOut (rPS.hdc,
  314.         (dx-LOWORD(dwExtent))/2,(dy-HIWORD(dwExtent))/2,
  315.         ETO_OPAQUE | ETO_CLIPPED,
  316.         &rc2,
  317.         ach,4,NULL);
  318.  
  319.             EndPaint(hWnd,(LPPAINTSTRUCT)&rPS);
  320.         return 0L;
  321.     }
  322.     return DefWindowProc(hWnd,uiMessage,wParam,lParam);
  323. }
  324.  
  325. /*----------------------------------------------------------------------------*\
  326. |   ProOpen ()                                       |
  327. |                                                                              |
  328. |   Description:                                                               |
  329. |                                                                              |
  330. |   Arguments:                                                                 |
  331. |                                                                              |
  332. |   Returns:                                                                   |
  333. |       0 if processed, nonzero if ignored                                     |
  334. |                                                                              |
  335. \*----------------------------------------------------------------------------*/
  336. HWND PUBLIC ProOpen(HWND hWnd, int id)
  337. {
  338.     if (id == NULL)
  339.        id = DLG_PROGRESS;
  340.  
  341.     iCnt++;
  342.     if (!ghWnd) {
  343.        fpxProDlg  = MakeProcInstance ((FARPROC)ProDlgProc,hInstWS);
  344.        ghWnd = CreateDialog(hInstWS,MAKEINTRESOURCE(id),hWnd,fpxProDlg);
  345.        WinAssert(ghWnd);
  346.        ShowWindow (ghWnd,SHOW_OPENWINDOW);
  347.        UpdateWindow(ghWnd);
  348.     }
  349.     ProSetBarRange(100);
  350.     ProSetBarPos(0);
  351.     return ghWnd;
  352. }   
  353.  
  354. /*----------------------------------------------------------------------------*\
  355. |   ProClose ()                                    |
  356. |                                                                              |
  357. |   Description:                                                               |
  358. |                                                                              |
  359. |   Arguments:                                                                 |
  360. |                                                                              |
  361. |   Returns:                                                                   |
  362. |       0 if processed, nonzero if ignored                                     |
  363. |                                                                              |
  364. \*----------------------------------------------------------------------------*/
  365. BOOL PUBLIC ProClose()
  366. {
  367.    iCnt--;
  368.    if (ghWnd && iCnt == 0) {
  369.       DestroyWindow (ghWnd);
  370.       FreeProcInstance (fpxProDlg);
  371.       ghWnd = NULL;
  372.    }
  373.    return TRUE;
  374. }
  375.  
  376. BOOL PUBLIC ProSetText (int i,LPSTR lpch)
  377. {
  378.     if (ghWnd) {
  379.     SetDlgItemText (ghWnd,i,lpch);
  380.     return TRUE;
  381.     }
  382.     return FALSE;
  383. }
  384.  
  385. BOOL FAR cdecl ProPrintf (int i, LPSTR lpch, ...)
  386. {
  387.     char ach[200];
  388.     if (ghWnd) {
  389.         wvsprintf(ach, lpch, (LPSTR)(&lpch+1));
  390.     SetDlgItemText(ghWnd, i, ach);
  391.     return TRUE;
  392.     }
  393.     return FALSE;
  394. }
  395.  
  396. BOOL PUBLIC ProSetBarRange (int i)
  397. {
  398.     if (ghWnd) {
  399.         SendDlgItemMessage(ghWnd,ID_BAR,BAR_SETRANGE,i,0L);
  400.     return TRUE;
  401.     }
  402.     return FALSE;
  403. }
  404.  
  405. BOOL PUBLIC ProSetBarPos (int i)
  406. {
  407.     if (ghWnd) {
  408.         SendDlgItemMessage(ghWnd,ID_BAR,BAR_SETPOS,i,0L);
  409.     return TRUE;
  410.     }
  411.     return FALSE;
  412. }
  413.  
  414. BOOL PUBLIC ProDeltaPos (int i)
  415. {
  416.     if (ghWnd) {
  417.         SendDlgItemMessage(ghWnd,ID_BAR,BAR_DELTAPOS,i,0L);
  418.     return TRUE;
  419.     }
  420.     return FALSE;
  421. }
  422.